package lunadevs.luna.module.exploits;

import java.util.List;

import org.lwjgl.input.Keyboard;

import lunadevs.luna.category.Category;
import lunadevs.luna.main.Luna;
import lunadevs.luna.module.Module;
import lunadevs.luna.utils.EntityUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.network.play.client.C07PacketPlayerDigging;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;

public class ArmorBreaker extends Module {
	int newtarget = 0;
	int delay;
	public static float yaw;
	public static float pitch;
	public static boolean active;

	public ArmorBreaker() {
		super("ArmorBreaker", Keyboard.KEY_NONE, Category.EXPLOITS, false);
	}

	public void onEnable() {
		active = true;
			Luna.addChatMessage("§7You need at least 2 swords to break armor. §7Use §7Killaura §7to §7break §7armor §7faster.");
		this.delay = 0;
		super.onEnable();
	}

	public void onUpdate() {
		if (!this.isEnabled) {
			return;
		}
		List list = this.mc.theWorld.playerEntities;

		this.delay += 1;
		for (int k = 0; k < list.size(); k++) {
			if ((this.newtarget < 2) && (((EntityPlayer) list.get(k)).getName() != Minecraft.thePlayer.getName())) {
				EntityPlayer entityplayer = (EntityPlayer) list.get(1);
				if (Minecraft.thePlayer.getDistanceToEntity(entityplayer) > Minecraft.thePlayer
						.getDistanceToEntity((Entity) list.get(k))) {
					entityplayer = (EntityPlayer) list.get(k);
					this.newtarget = 0;
				}
				float f = Minecraft.thePlayer.getDistanceToEntity(entityplayer);
				if ((f < 6.1D) && (!entityplayer.isInvisible()) && (entityplayer.isEntityAlive())) {
					if (entityplayer.isInvisible()) {
						continue;
					}
					if (this.delay > 0) {
						EntityUtils.faceEntity(entityplayer);
						if (Minecraft.thePlayer.isBlocking()) {
							Minecraft.thePlayer.sendQueue.addToSendQueue(
									new C07PacketPlayerDigging(C07PacketPlayerDigging.Action.RELEASE_USE_ITEM,
											new BlockPos(0, 0, 0), EnumFacing.UP));
						}
						this.mc.playerController.attackEntity(Minecraft.thePlayer, entityplayer);

						Minecraft.thePlayer.swingItem();
						this.delay = 0;
					}
				}
			}
		}
		super.onUpdate();
	}

	public void onDisable() {
		active = false;
		super.onDisable();
	}

	public String getValue() {
		return null;
	}
}
